# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
@Author : Ayao
@Time   : 2022/5/27
@File   : 寻找峰值.py
"""
# https://leetcode.cn/leetbook/read/binary-search/xem7js/
from typing import List

nums = [1, 2, 4, 5, 3, 9, 1]
nums = [1, 4, 3, 5, 6, 7]


class Solution:
    def findPeakElement(self, nums: List[int]) -> int:
        left, right = 0, len(nums) - 1
        while left < right:
            mid = left + (right - left) // 2
            if nums[mid] < nums[mid + 1]:
                left = mid + 1
            if nums[mid] > nums[mid + 1]:
                right = mid
        return left


print(Solution().findPeakElement(nums))
